package com.wmm.dao;

import com.wmm.bean.User;
import com.wmm.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class UserDaoImp implements UserDao {

    public UserDaoImp() {
    }

    @Override
    public User userLogin(User user)  {
        //1.创建QueryRunner对象 自动模式,传入数据库连接池
        try {
            QueryRunner qr = new QueryRunner(DruidUtils.dataSource);

            //2.编写SQL
            String sql = "select * from user where username = ? and password = ?";

            //3.执行update, 不需要传入连接对象
            User query = qr.query(sql, new BeanHandler<User>(User.class), user.getUserName(), user.getPassWord());
            System.out.println(query.toString());
            return query;
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }
}
